#include "Egg.h"


Egg::Egg(void) : mActive(false)
{
}

Egg::~Egg(void)
{
}

void Egg::Load()
{
	mSprite.Load("gdeggs.png");
}

void Egg::Unload()
{
	mSprite.Unload();
}

void Egg::Update(float deltaTime)
{
	mPosition += mVelocity * deltaTime;
}

void Egg::Render(const SVector2& viewOffset)
{
	const int kWinWidth = IniFile_GetInt("WinWidth", 800);
	const int kWinHeight = IniFile_GetInt("WinHeight", 600);
	const float limitY = IniFile_GetInt("WinHeight", 600);
	const int kThreshold = kWinHeight - mSprite.GetHeight();
	if(mActive)
	{
		const int width = mSprite.GetWidth();
		const int height = mSprite.GetHeight();
		SVector2 offset(width * 0.5f, height * 0.5f);
		SVector2 renderPosition = mPosition - offset - viewOffset;
		if(renderPosition.y >= kWinHeight - 100)
		{
			mSprite.Unload();
			mSprite.Load("broken_egg_temp.png");
			mSprite.SetPosition(renderPosition.x, limitY - 50);
			mSprite.Render();
		}
		else
		{
			mSprite.SetPosition(renderPosition);
			mSprite.Render();
		}
	}
}

void Egg::Spawn(const SVector2& pos, const SVector2& vel)
{
	mPosition = pos;
	mVelocity = vel;
	mActive = true;
}

void Egg::Kill()
{
	mActive = false;
}